from init_prepare_mod import init_prepare
from apscheduler.schedulers.background import BackgroundScheduler
from connect import connect_md, end_receive
from basic_params import exchange_url

sched = BackgroundScheduler(misfire_grace_time=5)


def fuc_MD():

    sched.add_job(init_prepare, 'cron', hour=str(8), minute=str(0), second=str(0),
                  id='t1', args=[exchange_url], misfire_grace_time=5)  # 8:0:0 确认是否为交易日,完成设置动作 init_prepare中time_flag_设置启动应该在connect_md之后

    sched.add_job(connect_md, 'cron', hour=str(8), minute=str(57), second=str(0),
                  id='t2', misfire_grace_time=5)  # 8：57：00确认当天是否启动接口对接交易所，启动后自动在OnRspUserLogin订阅全部合约 ctp经过Binfo.keep_connect_seconds（60*60*7）自动释放
    sched.add_job(connect_md, 'cron', hour=str(20), minute=str(57), second=str(0),
                  id='t3', misfire_grace_time=5)  # 20：57：00

    sched.add_job(end_receive, 'cron', hour=str(2), minute=str(30), second=str(5),
                  id='t4', misfire_grace_time=5)  # 2：30：5确认当天是否发送行情结束消息 开始储存、打包上传
    sched.start()
